using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Main;

namespace AtletIS.Database.Mapping.Main
{
    public class PerformanceMap : EntityTypeConfiguration<Performance>
    {
        public PerformanceMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.FirstName)
                .HasMaxLength(50);

            this.Property(t => t.Surname)
                .HasMaxLength(50);

            this.Property(t => t.Club)
                .HasMaxLength(100);

            this.Property(t => t.CountryId)
                .HasMaxLength(3);

            this.Property(t => t.SMS)
                .HasMaxLength(20);

            this.Property(t => t.ResultQuality)
                .HasMaxLength(10);

            this.Property(t => t.Reaction)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Performances");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.DisciplineListId).HasColumnName("DisciplineListId");
            this.Property(t => t.CompetitorId).HasColumnName("CompetitorId");
            this.Property(t => t.FirstName).HasColumnName("FirstName");
            this.Property(t => t.Surname).HasColumnName("Surname");
            this.Property(t => t.Birthdate).HasColumnName("Birthdate");
            this.Property(t => t.Club).HasColumnName("Club");
            this.Property(t => t.CountryId).HasColumnName("CountryId");
            this.Property(t => t.SMS).HasColumnName("SMS");
            this.Property(t => t.StartNumber).HasColumnName("StartNumber");
            this.Property(t => t.Lane).HasColumnName("Lane");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.SB).HasColumnName("SB");
            this.Property(t => t.PB).HasColumnName("PB");
            this.Property(t => t.Result).HasColumnName("Result");
            this.Property(t => t.ResultQuality).HasColumnName("ResultQuality");
            this.Property(t => t.AdvResult).HasColumnName("AdvResult");
            this.Property(t => t.Rank).HasColumnName("Rank");
            this.Property(t => t.SecondaryRank).HasColumnName("SecondaryRank");
            this.Property(t => t.Reaction).HasColumnName("Reaction");
            this.Property(t => t.Points).HasColumnName("Points");
            this.Property(t => t.Active).HasColumnName("Active");
            this.Property(t => t.Sync).HasColumnName("Sync");
            this.Property(t => t.WebId).HasColumnName("WebId");
            this.Property(t => t.Modified).HasColumnName("Modified");

            // Relationships
            this.HasOptional(t => t.Competitor)
                .WithMany(t => t.Performances)
                .HasForeignKey(d => d.CompetitorId);
            this.HasOptional(t => t.Country)
                .WithMany(t => t.Performances)
                .HasForeignKey(d => d.CountryId);
            this.HasOptional(t => t.DisciplineList)
                .WithMany(t => t.Performances)
                .HasForeignKey(d => d.DisciplineListId);
            this.HasOptional(t => t.ResultCode)
                .WithMany(t => t.Performances)
                .HasForeignKey(d => d.Code);

        }
    }
}
